#include "Image.h"

U32 Image::GetPix(S32 nRow, S32 nCol) const
{
	if (nRow >= m_nHeight || nRow < 0 || nCol >= m_nWidth || nCol < 0)
		return 0; /* change return value? */ 
	return *(m_pData + nRow * m_nWidth + nCol);
}

void Image::SetPix(S32 nRow, S32 nCol, U8 nColor)
{
	if (nRow < m_nHeight && nRow >= 0 && nCol < m_nWidth && nCol >= 0)
		*(m_pData + nRow * m_nWidth + nCol) = nColor;
}

Image::Image(U32 nWidth, U32 nHeight)
{
	m_pData = new U8[nWidth * nHeight];
	m_nWidth = nWidth;
	m_nHeight = nHeight;
}

void Image::ColorSwitch(U8 nSrc, U8 nDest)
{
	U8 *p = m_pData;
	U32 m_nSize = m_nWidth * m_nHeight;
	while(m_nSize--) {
		*p = *p == nSrc ? nDest : *p;
		p++;
	}
}
